
import * as XLSX from 'xlsx'
import ExportJsonExcel from 'js-export-excel'
import { Tag } from 'antd';

// 导航栏
const layout = [{
    name: "首页",
    path: '/home'
  },
  {
    name: "数据管理",
    path: "/datamanagment"
  },
  {
    name: "用户管理",
    path: "/usermanagment"
  },
  {
    name: "日志管理",
    path: "/logmanagment"
  }
]

//部门数据
const department = [{
  value: '研发部',
  },
  {
    value: '市场部',
  },
  {
    value: '销售部',
  },
  {
    value: '财务部',
  },
  {
    value: '人力资源部',
  },
  {
    value: '生产部',
  }]

/* 角色 */
const roles = [{
  value: '普通用户',
  },
  {
    value: '管理员',
  }]

/*车牌颜色 */
const plateColor = [{
  value: '不限',
  },
  {
    value: '蓝色',
  },
  {
    value: '白色',
  },
  {
    value: '绿色',
  },
  {
    value: '黑色',
  },
]
/* 车辆分组 */
const carGroup = [{
  value: '不分组',
  },
  {
    value: '按照车牌分组',
  },
  {
    value: '按照点位分组',
  },
  {
    value: '按照车辆品牌分组',
  },
]
/* 车辆点位 */
const carPoint = [{
  value: '1',
  },
  {
    value: '2',
  },
  {
    value: '3',
  },
]



// 定义时间
const day = new Date().getTime() + 24 * 60 * 60 * 1000 //一天
const hour = new Date().getTime() + 1 * 60 * 60 * 1000 //一小时

//获取剩余时间
function getRemainTime(time) {
  time = parseInt(time)
  var nowTime = +new Date() //获取当前时间戳
  var inputTime = +new Date(time) //获取用户输入的时间戳
  var times = (inputTime - nowTime) / 1000; //剩余时间（秒数）1s=1000ms
  // var d = parseInt(times / 60 / 60 / 24); //天数
  var h = parseInt(times / 60 / 60 % 24); //小时数
  var m = parseInt(times / 60 % 60); //分钟数
  var s = parseInt(times % 60); //秒数
  return (h + '时' + m + '分' + s + '秒');
};
//时间格式化
Date.prototype.format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1,                 //月份 
    "d+": this.getDate(),                    //日 
    "h+": this.getHours(),                   //小时 
    "m+": this.getMinutes(),                 //分 
    "s+": this.getSeconds(),                 //秒 
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
    "S": this.getMilliseconds()             //毫秒 
  };
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  }
  for (var k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    }
  }
  return fmt;
}    

/* 用户管理数据 */
const usercolumns = [
  {
    title: '序号',
    key:"id",
    dataIndex: 'id',
    render: text => <p>{text}</p>,
  },
  {
    title: '账号',
    key: "account",
    dataIndex: 'account',
    render: (_, record) => (
     <p>
      {record.role===1?"admin":"user"}
     </p>
    ),
  },
  {
    title: '用户名',
    key: "username",
    dataIndex: 'username',
    render: text => <p>{text}</p>,
  },
  {
    title: '身份证号',
    key:"id_card",
    dataIndex: 'id_card',
    render: text => <p>{text}</p>,
  },
  {
    title: '电话号码',
    key:"phone",
    dataIndex: 'phone',
    render: text => <p>{text}</p>,
  },
  {
    title: '部门',
    key: "department",
    dataIndex: 'department',
    render: text => <p>{text}</p>,
  },
  {
    title: '角色',
    key:"role",
    dataIndex: 'role',
    render: text => <p>{text === 0 ? "普通用户" : "管理员"}</p>,
  },

  {
    title: '操作',
    key:"action",
    dataIndex: 'action',
  },
];


/* 数据导出 */
const downloadFileToExcel = (data,header) => {
  let option = {};                             //option代表的就是excel文件
  option.fileName = '车辆数据表';               //excel文件名称
  option.datas = [
    {
      sheetData: data,                          //excel文件中的数据源
      sheetName: 'demo',                         //excel文件中sheet页名称
      sheetHeader: header
    }
  ]
  let toExcel = new ExportJsonExcel(option);      //生成excel文件
  toExcel.saveExcel();                             //下载excel文件
}

/* 日志检索条件 */
const logsearch = [
  {
    value: '不限',
  },
{
  value: '姓名',
},
{
  value: '所属部门',
},
{
  value: '功能模块',
},
{
  value: '搜索条件',
},
{
  value: 'ip',
},
]

/* 日志管理数据 */
const logcolumns = [
  {
    title: "序号",
    dataIndex: "key",
    key: "key",
    render: text => <p>{text}</p>,
  },
  {
    title: '姓名',
    key: "username",
    dataIndex: 'username',
    render: text => <p>{text}</p>,
  },
  {
    title: '所属部门',
    key: "department",
    dataIndex: 'department',
    render: text => <p>{text}</p>,
  },
  {
    title: '功能模块',
    key: "function_module",
    dataIndex: 'function_module',
    render: text => <p>{text}</p>,
  },
  {
    title: '搜索条件',
    key: "search_condation",
    dataIndex: 'search_condation',
    width:100,
    render: text => <p>
      {text===""? "":
        <Tag color="skyblue">
          {text}
        </Tag>
      }
    </p>,
  },
  {
    title: 'ip',
    key: "ip",
    dataIndex: 'ip',
    render: text => <p>{text}</p>,
  },
  {
    title: '操作',
    key: "handle",
    dataIndex: 'handle',
    
    render: text => <p>
      <Tag color="blue">
        {text}
      </Tag>

    </p>,
  },
  {
    title: '操作状态',
    key: "handle_status",
    dataIndex: 'handle_status',
    render: (_, record) => (

      <p>
        <Tag color={record.handle_status === 1 ? "green" : "volcano"}>
          {record.handle_status === 1 ? "成功" : "失败"}
        </Tag>

      </p>
    ),
  },

  {
    title: '操作时间',
    key: "handle_time",
    dataIndex: 'handle_time',
    render: text => <p>{text}</p>,
  },
];


export {
  layout,
  department,
  day,
  hour,
  usercolumns,
  getRemainTime,
  roles,
  plateColor,
  carGroup,
  carPoint,
  downloadFileToExcel,
  logsearch,
  logcolumns,
}